<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
<%@ page import="com.atozsoft.commonutil.Constants"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 
  - Author(s): Administrator
  - Date: 2014-11-14 16:18:56
  - Description:
-->
<head>
<title>流程节点按钮列表</title>
    <%@include file="/common.jsp"%>
	<%@include file="/common/common.jsp"%>
    <%@include file="/coframe/tools/skins/common.jsp" %>
	<style type="text/css">
    html, body{
        margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
    }    
    </style>
</head>
<body>
 <div style="padding-top:5px">
	<div id="addAsCustomerForm" style="margin-top:5px;">
		<div id="datagrid1" class="nui-datagrid" style="width:100%;height:280px" 
       		 url="data/nodeButtonList.txt" idField="buttonId" dataField="nodeButtonList"
       		 allowResize="true" showPager="false" onlyCheckSelection="false"
      	     allowCellEdit="true" allowCellSelect="true" multiSelect="true"  
      		 allowCellValid="true">
	        <div property="columns">
	             <div type="checkcolumn" ></div>        
	            <div field="buttonName"  width="120" headerAlign="center">按钮默认名称
	            </div>                
	            <div field="buttonAlias" vtype="maxLength:200" width="100"  headerAlign="center">别名
	                <input property="editor" class="nui-textbox"  style="width:100%;" />
	            </div>
	        </div>
	    </div>
        <div class="nui-toolbar" style="text-align:center;padding-top:5px;padding-bottom:5px;" borderStyle="border:0;">
	        <a class="nui-button" style="width:60px;" iconCls="icon-save" onclick="onOk()">确定</a>
	        <span style="display:inline-block;width:25px;"></span>
	        <a class="nui-button" style="width:60px;" iconCls="icon-cancel" onclick="onCancel()">取消</a>
	    </div>        
    </div>
</div>


	<script type="text/javascript">
    	nui.parse();
    	var grid = nui.get("datagrid1");
    	var buttonDataList = new Array(); //存放选择的按钮
    	var dataButtonList = [
    	            {
    	                "buttonId": "1","buttonName":"抄送","buttonAlias":""
    	            },
					{
						"buttonId": "2","buttonName":"退回","buttonAlias":""
					},
					{
						"buttonId": "3","buttonName":"撤回","buttonAlias":""
					},
					{
						"buttonId": "4","buttonName":"终止","buttonAlias":""
					},
					/* {
						"buttonId": "5","buttonName":"加审","buttonAlias":""
					},
					{
						"buttonId": "6","buttonName":"转发","buttonAlias":""
					}, */
					{
						"buttonId": "7","buttonName":"同意","buttonAlias":""
					}/* ,
					{
						"buttonId": "8","buttonName":"打印","buttonAlias":""
					},
					{
						"buttonId": "9","buttonName":"撤销","buttonAlias":""
					},
					{
						"buttonId": "10","buttonName":"保存","buttonAlias":""
					},
					{
						"buttonId": "11","buttonName":"编辑","buttonAlias":""
					} */
					];
    	
    	//初始化
       function SetData(data){
    	var data = nui.clone(data);
    	    data = nui.decode(data);
    	var buttonStr = data.buttonStr;    
    	if(buttonStr != null || buttonStr != ""){
    	  var buttonArray = (buttonStr.indexOf(",") > 0)?buttonStr.split(","):buttonStr; //将按钮信息转换为数组
		     for(var i=0,len =buttonArray.length;i<len;i++){ //获取按钮的Id和名称
		         var bData = buttonArray[i];
                 var n = bData.indexOf("-");
                 var  bId = bData.substring(0,n);
                 var  bName = bData.substring(n+1);
                
                for(var j=0,lenJ=dataButtonList.length;j<lenJ;j++){ //给原始数据的buttonAlias字段赋值
                  var bObj = dataButtonList[j];
                  if(bId == bObj.buttonId){
                    bObj.buttonAlias = (bName != bObj.buttonName)?bName:""; //如果别名和原始名称相同则别名为空
                    break;
                  }
                }
		     }
    	}   
    	grid.setData(dataButtonList);
    	    
    	//grid.load();
    	
    	if(buttonStr != null || buttonStr != ""){
    	   buttonStr = "," + buttonStr + ",";
    	   grid.on("drawcell", function (e) { //设置选中的按钮以及别名      每次更改别名之后都会触发该事件
			   var record = e.record,
			       row = e.row;
				if (record != null) {
				     var bId = record.buttonId;
				     var bIdStr = "," + bId + "-";
				     var num = buttonStr.indexOf(bIdStr);  //判断当前按钮是否被选中
				     if(num > -1){
				       	grid.select(row);
				     
				     }  
			    }
			});
    	}
       }
    	
    	//保存
    	function onOk(){
    	   grid.validate();
            if (grid.isValid() == false) {
                return;
            }

          var rows = grid.getSelecteds();    
          if(rows.length > 0){
             for(var i=0,len=rows.length;i<len;i++){ //获取选中的按钮，通过Id和name的组合存放到数组中
               var buttonId = rows[i].buttonId;
               var buttonName = rows[i].buttonName;
               var buttonAlias = rows[i].buttonAlias;
               var buttonData = buttonId +"-"+ (buttonAlias || buttonName);
                  buttonDataList.push(buttonData);
             }
          }
           CloseWindow("ok");
    	}
    	//返回数据
    	function GetData(){
    	 return buttonDataList;
    	}
    	
    	//取消
    	function onCancel(){
    	    CloseWindow("cancel");
    	}
    	function CloseWindow(action) {
	        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	        else window.close();
	    }
	   
    </script>
</body>
</html>